extends Panel
var coord = []

@export var threat_higthlight: Sprite2D
@export var threat_value_label: Label

var threat_source_count = 0
var threat_value = 0

func _ready():
	update_threat_display()

func _on_pressed(): # 点击时，根据Chessboard的状态进行判断，要执行什么逻辑
	# print(coord)
	if Chessboard.board_state == Chessboard.STATE.PLAYER_MOVE:
		Chessboard.focus_player.try_move_player(coord)
	elif Chessboard.board_state == Chessboard.STATE.CARD_ACTION:
		Chessboard.focus_card.try_play_this_card(coord)

func _on_mouse_entered():
	# 角色移动状态下，鼠标悬停时，计算当前focus_player移动到这里所需要的cost
	if Chessboard.focus_player != null and Chessboard.board_state == Chessboard.STATE.PLAYER_MOVE:
		var piece = Chessboard.board_array[coord[0]][coord[1]]
		if piece == null or not piece.is_block:
			var cost = Chessboard.focus_player.calculate_move_cost(coord)
			$Button.text = str(cost)

func _on_mouse_exited(): 
	# 鼠标离开时，显示的数字清掉
	$Button.text = "" 

# 以下两个func用于显示格子上的威胁值
# 更新数值，由enemy调用
func update_threat(source_count_in, value_in):
	threat_source_count += source_count_in
	threat_value += value_in
	update_threat_display()

# 更新威胁显示
func update_threat_display():
	threat_higthlight.visible = threat_source_count > 0
	threat_value_label.visible = threat_value > 0
	threat_value_label.text = str(threat_value)
